<?php

namespace app\index\command;

use think\console\Command;
use think\console\Input;
use think\console\Output;
use app\index\model\Image;

class Flush extends Command
{
    protected function configure()
    {
        $this->setName('image:flush')->setDescription('Flush through the database to generate images');
    }

    protected function execute(Input $input, Output $output)
    {
        // 进入tensorFlow
        chdir('tensorflow');
        // 不断地刷
        while (true) {
            // 查询未生成的图像
            $query = new Image();
            $res = $query->where('image_status', Image::$STATUS_GENERATING)->select();
            foreach ($res as $r) {
                // 完成图像风格迁移
                $model = Image::$STYLE_RELATION[$r->image_style];
                $file = $r->image_code . '.' . $r->image_type;
                `python eval.py --model_file models/{$model}.ckpt-done --input_file ../public/input/{$file} --output_file ../public/output/{$file}`;
                // 修改数据库
                $r->image_status = Image::$STATUS_GENERATED;
                $r->save();
            }
            $output->writeln('Finish generating for single turn.');
            sleep(1);
        }
    }
}
